import java.util.Observable;
import java.util.Observer;

public class Lunch extends Event implements Observer
{
	private final TimeDuration duration;
	private Time endOfLunch = null;
	private final Schedule schedule;

	public Lunch(Time eventTime, Employee member, TimeDuration duration)
	{
		super(eventTime, member);
		this.duration = duration;
		this.schedule = member.getSchedule();
		priority = 1;
	}

	@Override
	synchronized public void run()
	{
		Employee employee = (Employee) Thread.currentThread();
		schedule.notifyMeIn(duration, this);
		try
		{
			wait();
		}
		catch (InterruptedException e)
		{
			e.printStackTrace();
		}
		String message = (endOfLunch.toString() + " " + employee.toString()
			+ " returned from lunch");
		PrintBuffer.printMessage(schedule.getCurrentTime(), message);
	}

	@Override
	public String toString()
	{
		return "went to lunch";
	}

	@Override
	synchronized public void update(Observable observable, Object arg)
	{
		endOfLunch = (Time) arg;
		notify();
	}

}
